﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>出差休假</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="/CSS/Base/BaseClass.css?cssver=4" rel="stylesheet" type="text/css" />
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/Scripts/jquery-migrate-1.1.0.min.js"></script>
    <script src="/JqueryPlug/layer/layer/layer.js"></script>
    <script src="/Scripts/avalon.min.js"></script>
    <script src="/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
    <script src="/Scripts/SZHLCommon.js?jsver=5"></script>
    <style>
        .pCard {
            min-width: 80px;
            text-align: center;
            margin: 0 5px 5px 5px;
        }
    </style>
    <script>
        var processId = ComFunJS.getQueryString("PDID");
        var model = avalon.define({
            $id: "APP_WF_LCSZ",
            modelData: {},
            RoleData: [],
            LCItem: { TaskName: "提出申请", Taskorder: "", AssignedRole: "", TaskAssInfo: "", NodeType: "NODE", ProcessDefinitionID: processId, isSJ: "N", TDCODE: "" },
            LCItemList: [{ TaskName: "提出申请", Taskorder: "1", AssignedRole: "", TaskAssInfo: "", NodeType: "START", ProcessDefinitionID: processId, isSJ: "N", TDCODE: processId + "-1" }],//固定流程数据
            addjd: function () {
                if (model.LCItem.TaskAssInfo == "") {
                    parent.ComFunJS.winwarning("请选择节点处理人");
                    return;
                }
                if (model.LCItem.NodeType == "END") { 
                    $("#addwf").css("display", "none")
                }
                model.LCItem.Taskorder = model.LCItemList.size() + 1;
                model.LCItem.TDCODE = model.LCItem.ProcessDefinitionID + "-" + model.LCItem.Taskorder;
                model.LCItemList.push(model.LCItem.$model);
                model.LCItem = { TaskName: "提出申请", Taskorder: "", AssignedRole: "", TaskAssInfo: "", NodeType: "NODE", ProcessDefinitionID: processId, isSJ: "N", TDCODE: "" };
            },
            deljd: function (item) {
                if (item.NodeType == "END") {
                    $("#addwf").css("display", "block")
                }
                model.LCItemList.remove(item);
            },
            AddLCSZ: function () {
                var modelValue;
                if (model.modelData.ProcessType == 0) {
                    modelValue = JSON.stringify(model.modelData.$model)
                    $.post("/API/FTAPI.ashx", { Action: "ADDPROCESS", P1: modelValue },
                    function (result) {
                        if ($.trim(result.ErrorMsg) != "") {
                            parent.ComFunJS.winwarning(result.ErrorMsg);
                        } else {
                            parent.ComFunJS.winsuccess("设置成功");
                        }
                    });
                } else {
                    modelValue = JSON.stringify(model.LCItemList.$model)
                    $.post("/API/FTAPI.ashx", { Action: "ADDTDINFO", P1: modelValue },
                           function (result) {
                               if ($.trim(result.ErrorMsg) != "") {
                                   parent.ComFunJS.winwarning(result.ErrorMsg);
                               } else {
                                   parent.ComFunJS.winsuccess("设置成功");
                               }
                           });
                }

            }, SelRole: function (item) {
                if (item.NodeType == "START")
                {
                    return;
                }
                ComFunJS.winbtnwin("/View/Base/RoleSelect.html?checkvalue=", "选择角色", 700, 400, {}, function (layero, index) {
                    var frameid = $("iframe", $(layero)).attr('id');
                    var people = window.frames[frameid].getqiandaopeople();
                    item.AssignedRole = people.RoleCode;
                    item.TaskAssInfo = people.RoleName;
                    layer.close(index)
                })
            }
            , GetNodeTypeName: function (nodeType) {
                var nodeName = "";
                if (nodeType == "START")
                {
                    nodeName = "开始节点";
                }
                if (nodeType == "NODE") {
                    nodeName = "中间节点";
                }
                if (nodeType == "END") {
                    nodeName = "结束节点";
                }
                return nodeName;
        }
        })
        avalon.ready(function () {
          
            if (processId) {
                //编辑加载数据
                $.getJSON('/API/FTAPI.ashx?Action=GETPROCESSBYID', { P1: processId }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.modelData = resultData.Result;
                        if (!model.modelData.ProcessType) {
                            model.modelData.ProcessType = 0;
                        }
                        setTimeout(" ComFunJS.initForm()", 500)
                    }
                })
                //编辑加载数据
                $.getJSON('/API/SZHLAPI.ashx?Action=GETROLE', function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.RoleData = resultData.Result;
                    }
                })
                //编辑加载数据
                $.getJSON('/API/FTAPI.ashx?Action=GETTDLIST', { P1: processId }, function (resultData) { 
                    if (resultData.ErrorMsg == "") {
                        if (resultData.Result.length > 0) {
                            model.LCItemList = resultData.Result;
                            model.LCItemList.forEach(function (val) {
                                if (val.NodeType == "END")
                                {
                                    $("#addwf").css("display", "none")
                                }
                            })
                        }
                    }
                })
            }
        })
    </script>
</head>
<body ms-controller="APP_WF_LCSZ">
    <div class="container-fluid maindiv" style="margin-top: 20px" id="dvContent">
        <div class="row contentdv" style="margin-left:20px">
            <div class="col-xs-12 ">
                <div class="panel panel-default">
                    <div class="panel-heading"><span>审核流程信息</span></div>
                    <div class="panel-body">
                        <div class="form-group">
                            <label>流程类型{{LCItem.ProcessDefinitionID}}</label>
                            <select class="form-control" ms-duplex="modelData.ProcessType" ms-attr-disabled="LCItem.ProcessDefinitionID<3?'true':''">
                                <option value="0" ms-attr-selected="modelData.ProcessType==0?'selected':''">自由流程</option>
                                <option value="1" ms-attr-selected="modelData.ProcessType==1?'selected':''">固定流程</option>

                            </select>
                        </div>
                        <div class="form-group" ms-if="modelData.ProcessType==0">
                            <label>审核人</label>
                            <input type="text" ms-duplex="modelData.Alias" class="form-control szhl_getPeoples" />
                        </div>
                        <table class="table table-striped table-hover table-bordered" ms-if="modelData.ProcessType==1">
                            <thead>
                                <tr>
                                    <th>节点步骤</th>
                                    <th>节点名称</th>
                                    <th>节点类型</th>
                                    <th>节点处理角色</th>
                                    <th>是否上级</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ms-repeat-item="model.LCItemList">
                                    <td>{{item.Taskorder}}</td>
                                    <td>{{item.TaskName}}</td>
                                    <td>{{GetNodeTypeName(item.NodeType)}}</td>
                                    <td ms-click="SelRole(item)">{{item.TaskAssInfo}}</td>
                                    <td>
                                        <select ms-duplex="item.isSJ" class="form-control">
                                            <option value="Y" ms-attr-selected="item.isSJ=='Y'">
                                                是
                                            </option>
                                            <option value="N" ms-attr-selected="item.isSJ=='N'">
                                                否
                                            </option>
                                        </select>
                                    </td>
                                    <td>
                                        <a class="btn btn-danger btn-xs" ms-click="deljd(item)"><i class="fa fa-trash-o"></i> 删除 </a>
                                    </td>
                                </tr>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <td>
                                        {{LCItemList.size()+1}}
                                    </td>
                                    <td><input type="text" class="form-control" ms-duplex="LCItem.TaskName" placeholder="节点名称"></td>
                                    <td>
                                        <select class="form-control" ms-duplex="LCItem.NodeType">
                                            <option value="NODE">中间节点</option>
                                            <option value="END">结束节点</option>
                                        </select>
                                    </td>
                                    <td>
                                        <input type="text" class="form-control" ms-click="SelRole(LCItem)" ms-duplex="LCItem.TaskAssInfo" placeholder="节点处理人">
                                    </td>
                                    <td>
                                        <select ms-duplex="LCItem.isSJ" class="form-control">
                                            <option value="Y">
                                                是
                                            </option>
                                            <option value="N">
                                                否
                                            </option>
                                        </select>
                                    </td>
                                    <td>
                                        <a class="btn btn-primary" id="addwf" ms-click="addjd()"><i class="fa fa-adjust"></i> 添加 </a>
                                    </td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
                <button class="btn btn-default" ms-click="AddLCSZ()">保存数据</button>
            </div>
        </div>
    </div>
    <link href="/JqueryPlug/umeditor122/themes/default/css/umeditor.css" type="text/css" rel="stylesheet" />
    <script src="/JqueryPlug/umeditor122/umeditor.js" type="text/javascript" charset="utf-8"></script>
    <script src="/JqueryPlug/umeditor122/umeditor.config.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
